package com.huawei.esdk.uc.jna.util;

import java.io.UnsupportedEncodingException;

public class StringUtil
{

    public static String bytesToString(byte[] arg0)
    {
        String result = "";
        try
        {
            result = new String(arg0, "GBK").trim();
        }
        catch (UnsupportedEncodingException exception)
        {
            exception.printStackTrace();
        }
        return result;
    }

    public static String bytesToUTF8String(byte[] arg0)
    {
        String result = "";
        try
        {
            result = new String(arg0, "UTF-8").trim();
        }
        catch (UnsupportedEncodingException exception)
        {
            exception.printStackTrace();
        }
        return result;
    }

    public static boolean isEmptyStr(String sourceStr)
    {
        if (null == sourceStr || sourceStr.length() == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public static int getValueForName(String[][] souce, String name)
    {
        String[] as;
        for (int i = 0; i < souce.length; i++)
        {
            as = souce[i];
            if (name.equals(as[0]))
            {
                return Integer.parseInt(as[1]);
            }
        }
        return Integer.parseInt(souce[0][1]);
    }

}
